package com.klamerek.rainbow.client.charts.geom;

public class MyInterval {

	private double value1;
	private double value2;
	
	private boolean strict;
	
	/**
	 * Constructor
	 * @param value1
	 * @param value2
	 */
	public MyInterval(double value1, double value2){
		this.value1 = value1;
		this.value2 = value2;
		this.strict = false;
	}
	
	/**
	 * Constructor
	 * @param value1
	 * @param value2
	 * @param strict
	 */
	public MyInterval(double value1, double value2, boolean strict){
		this.value1 = value1;
		this.value2 = value2;
		this.strict = strict;
	}
	
	public double getValue1() {
		return value1;
	}

	public void setValue1(double value1) {
		this.value1 = value1;
	}

	public double getValue2() {
		return value2;
	}

	public void setValue2(double value2) {
		this.value2 = value2;
	}

	public boolean isStrict() {
		return strict;
	}

	public void setStrict(boolean strict) {
		this.strict = strict;
	}

	/**
	 * For add a delta.
	 * @param delta
	 */
	public void addDelta(double delta){
		if (this.value1 > this.value2){
			this.value1 += delta;
			this.value2 -= delta;
		}else{
			this.value1 -= delta;
			this.value2 += delta;
		}
	}
	
	/**
	 * Check if the value is between value1 and value2.
	 * @param value
	 * @return
	 */
	public boolean contains(double value){
		boolean result = false;
		if (strict){
			if (this.value1 < value && value < this.value2
					|| this.value1 > value && value > this.value2){
				result = true;
			}
		}else{
			if (this.value1 <= value && value <= this.value2
					|| this.value1 >= value && value >= this.value2){
				result = true;
			}
		}
		return result;
	}
	
}
